Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
Looking to remove any value after :->

I am looking to remove any value after ':->' in JavaScript For example if 'Packet:->3', I would like to store "Packet:->" in the variable so I can use it before the if statement seen below. Pretty much I am looking to remove any digits after '>'

I was trying the below, but did not have much luck.

NTEremoved = NTE.indexOf(':->');

What would be the best way of doing this?

if(NTE == 'Packet:->' || NTE == 'Serving:->' || NTE == 'Can/Carton/Bottle:->'){

} 
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

String split.

const testStr1 = "Packet:->3";
const testStr2 = "BlahBlahBlah278:->Hello hello this is cool";
const result1 = testStr1.split(":->")[0] + ":->"; // split "splits" the string into an array based on the delimiter ":->"; the second part would be 3
const result2 = testStr2.split(":->")[0] + ":->";
console.log(result1);
console.log(result2);

Docs.

about 4 years ago · Juan Pablo Isaza Relatório

0

I would do something like this, to take care also of edge cases (assuming you don't care about what is coming after the first :->:

let texts = ["Packet:->11", "Cat:->22", "Packet:->:->:->44"];

for (let text of texts) {
  console.log(text.replace(/(:->).*$/, "$1"))
}

about 4 years ago · Juan Pablo Isaza Relatório

0

Since you have mentioned you have tries to use indexOf before but fail to do that, I will provide you a way using a combination of indexOf and String.slice

let string = "Serving:->3"
//Indexof return the first index of an element so you have to add 3 (the length of ":->"
let newstring = string.slice(0,string.indexOf(":->")+3)

console.log(newstring)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda